﻿
namespace TfsGiggle.Core
{
    /// <summary>
    /// Do a search
    /// </summary>
    public class Search : ISearch
    {
        /// <summary>
        /// Do a search
        /// </summary>
        /// <param name="userQuery"></param>
        /// <returns></returns>
        public QueryResultDTO Query(string userQuery)
        {
            if (string.IsNullOrWhiteSpace(userQuery)) return null;
            return JobManager.Instance.IndexModel.Query(userQuery);
        }

        /// <summary>
        /// Get number of documents in the index
        /// </summary>
        /// <returns></returns>
        public int GetNumberOfDocuments()
        {
            return JobManager.Instance.IndexModel.NumberOfDocuments;
        }

        /// <summary>
        /// Get this specific document from the index
        /// </summary>
        /// <param name="documentId"></param>
        /// <returns></returns>
        public QueryResultDTO GetDocument(int documentId)
        {
            return JobManager.Instance.IndexModel.GetDocument(documentId);
        }

        /// <summary>
        /// Get the contents of this file
        /// </summary>
        /// <param name="teamProjectCollectionId"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public string GetFile(string teamProjectCollectionId, string filePath)
        {
            return JobManager.Instance.IndexModel.GetFile(teamProjectCollectionId, filePath);
        }
    }
}
